/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * TransaksiPenjualan.java
 *
 * Created on Aug 11, 2010, 11:28:41 PM
 */
package com.ivanbiz.gui;

import com.ivanbiz.dao.PembelianDAO;
import com.ivanbiz.dao.ReturPembelianDAO;
import com.ivanbiz.helper.CenterRenderer;
import com.ivanbiz.helper.RightRenderer;
import com.ivanbiz.helper.ServiceHelper;
import com.ivanbiz.impl.PembelianDAOImpl;
import com.ivanbiz.impl.ReturPembelianDAOImpl;
import com.ivanbiz.model.ItemPembelian;
import com.ivanbiz.model.Pembelian;
import com.ivanbiz.model.ReturPembelian;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;

/**
 *
 * @author Aprisma
 */
public class FReturPembelian extends javax.swing.JInternalFrame {

    PembelianDAO pembelianDAO = new PembelianDAOImpl();
    ReturPembelianDAO returPembelianDAO = new ReturPembelianDAOImpl();
    List<ReturPembelian> listReturPembelian = new ArrayList<ReturPembelian>();
    List<ItemPembelian> listiItemPembelian = new ArrayList<ItemPembelian>();
    List<ReturPembelian> listReturPembelianTemp = new ArrayList<ReturPembelian>();
    NumberFormat numberFormat = NumberFormat.getInstance(Locale.US);
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd MMMM yyyy");

    /** Creates new form TransaksiPenjualan */
    public FReturPembelian() {
        initComponents();
        updateData();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        groupPilihan = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        labelTanggal = new javax.swing.JLabel();
        textTanggal = new javax.swing.JTextField();
        labelKode = new javax.swing.JLabel();
        textKode = new javax.swing.JTextField();
        labelPemasok = new javax.swing.JLabel();
        textPemasok = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        buttonProses = new javax.swing.JButton();
        buttonReset = new javax.swing.JButton();
        labelPT = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tableItemPembelian = new javax.swing.JTable();
        buttonOk = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tableReturPembelian = new javax.swing.JTable();
        buttonNo = new javax.swing.JButton();

        setBorder(new org.jdesktop.swingx.border.DropShadowBorder());
        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setTitle("Retur  Pembelian");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Pembelian"));

        labelTanggal.setFont(new java.awt.Font("Tahoma", 1, 11));
        labelTanggal.setText("Tanggal");

        textTanggal.setEditable(false);
        textTanggal.setFont(new java.awt.Font("Tahoma", 1, 11));
        textTanggal.setText("jTextField1");

        labelKode.setFont(new java.awt.Font("Tahoma", 1, 11));
        labelKode.setText("Kode");

        textKode.setFont(new java.awt.Font("Tahoma", 1, 11));
        textKode.setText("jTextField2");
        textKode.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                textKodeKeyPressed(evt);
            }
        });

        labelPemasok.setFont(new java.awt.Font("Tahoma", 1, 11));
        labelPemasok.setText("Pemasok");

        textPemasok.setEditable(false);
        textPemasok.setFont(new java.awt.Font("Tahoma", 1, 11));
        textPemasok.setText("jTextField1");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(labelTanggal)
                    .addComponent(labelKode)
                    .addComponent(labelPemasok))
                .addGap(57, 57, 57)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(textKode, javax.swing.GroupLayout.DEFAULT_SIZE, 172, Short.MAX_VALUE)
                    .addComponent(textTanggal, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 172, Short.MAX_VALUE)
                    .addComponent(textPemasok, javax.swing.GroupLayout.DEFAULT_SIZE, 172, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelTanggal)
                    .addComponent(textTanggal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textKode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelKode))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelPemasok)
                    .addComponent(textPemasok, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(18, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Tombol"));

        buttonProses.setFont(new java.awt.Font("Tahoma", 1, 11));
        buttonProses.setText("Prosess");
        buttonProses.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonProsesActionPerformed(evt);
            }
        });

        buttonReset.setFont(new java.awt.Font("Tahoma", 1, 11));
        buttonReset.setText("Reset");
        buttonReset.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonResetActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(buttonReset, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 578, Short.MAX_VALUE)
                .addComponent(buttonProses)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(buttonReset)
                    .addComponent(buttonProses))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        labelPT.setFont(new java.awt.Font("Tahoma", 1, 36));
        labelPT.setText("PT BERGUNA JAYA");

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Tabel Pembelian"));

        tableItemPembelian.setAutoCreateRowSorter(true);
        tableItemPembelian.setFont(new java.awt.Font("Tahoma", 1, 11));
        tableItemPembelian.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tableItemPembelian.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tableItemPembelianMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tableItemPembelian);

        buttonOk.setFont(new java.awt.Font("Tahoma", 1, 11));
        buttonOk.setText(">>");
        buttonOk.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonOkActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 323, Short.MAX_VALUE)
                    .addComponent(buttonOk))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 233, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(buttonOk)
                .addContainerGap())
        );

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel4.setText("Jln. Jembatan Selatan no 470 Panglima Polim Jakarta Selatan ");

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel5.setText("Telp : 08174820800");

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Tabel Retur Pembelian"));

        tableReturPembelian.setAutoCreateRowSorter(true);
        tableReturPembelian.setFont(new java.awt.Font("Tahoma", 1, 11));
        tableReturPembelian.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane2.setViewportView(tableReturPembelian);

        buttonNo.setFont(new java.awt.Font("Tahoma", 1, 11));
        buttonNo.setText("<<");
        buttonNo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonNoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 365, Short.MAX_VALUE)
                    .addComponent(buttonNo))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 233, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(buttonNo)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(labelPT)
                            .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, 449, Short.MAX_VALUE)
                            .addComponent(jLabel5))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(labelPT)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel5))
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-800)/2, (screenSize.height-550)/2, 800, 550);
    }// </editor-fold>//GEN-END:initComponents

    private void buttonProsesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonProsesActionPerformed
        try {
            returPembelianDAO.saveItemReturPembelian(listReturPembelianTemp);
            updateData();
        } catch (Exception ex) {
            Logger.getLogger(FReturPembelian.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_buttonProsesActionPerformed

    private void buttonOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonOkActionPerformed
        textKode.setEditable(false);
        float jumlah = Float.parseFloat(JOptionPane.showInputDialog(null, "Input Jumlah Retur", ""));
        ItemPembelian itemPembelian = listiItemPembelian.get(tableItemPembelian.getSelectedRow());
        if (jumlah > itemPembelian.getJumlah()) {
            JOptionPane.showMessageDialog(null, "Jumlah Melebihi batas Retur !!!");
        } else if (jumlah <= 0.0) {
            JOptionPane.showMessageDialog(null, "Jumlah Tidak Boleh Kurang atau sama dengan 0 !!!");
        } else {
            ReturPembelian returPembelian = new ReturPembelian();
            returPembelian.setCreateDate(ServiceHelper.getDateNow());
            returPembelian.setPembelian(itemPembelian.getPembelian());
            returPembelian.setBarang(itemPembelian.getBarang());
            returPembelian.setJumlah(jumlah);
            listReturPembelian.add(returPembelian);
            listReturPembelianTemp.add(returPembelian);
            updateTableReturPenjualan();
        }
    }//GEN-LAST:event_buttonOkActionPerformed

    private void buttonNoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonNoActionPerformed
        textKode.setEditable(false);
        listReturPembelian.remove(tableReturPembelian.getSelectedRow());
        listReturPembelianTemp.remove(tableReturPembelian.getSelectedRow());
        updateTableReturPenjualan();
    }//GEN-LAST:event_buttonNoActionPerformed

    private void textKodeKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_textKodeKeyPressed
        if (evt.getKeyCode() == 10) {
            try {
                textKode.setEditable(false);
                Pembelian pembelian = (Pembelian) pembelianDAO.getDataByEqual(Pembelian.class, "kode", textKode.getText().toUpperCase());
                textPemasok.setText(pembelian.getSupplier().getKode() + "( " + pembelian.getSupplier().getNama() + " )");
                listiItemPembelian = pembelian.getItemPembelian();
                updateTableItemNota();
                listReturPembelian = returPembelianDAO.getDataByEquals(ReturPembelian.class, "pembelian", pembelian);
                updateTableReturPenjualan();
            } catch (Exception ex) {
                Logger.getLogger(FReturPembelian.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }//GEN-LAST:event_textKodeKeyPressed

    private void tableItemPembelianMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tableItemPembelianMouseClicked
}//GEN-LAST:event_tableItemPembelianMouseClicked

    private void buttonResetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonResetActionPerformed
        updateData();
    }//GEN-LAST:event_buttonResetActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton buttonNo;
    private javax.swing.JButton buttonOk;
    private javax.swing.JButton buttonProses;
    private javax.swing.JButton buttonReset;
    private javax.swing.ButtonGroup groupPilihan;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel labelKode;
    private javax.swing.JLabel labelPT;
    private javax.swing.JLabel labelPemasok;
    private javax.swing.JLabel labelTanggal;
    private javax.swing.JTable tableItemPembelian;
    private javax.swing.JTable tableReturPembelian;
    private javax.swing.JTextField textKode;
    private javax.swing.JTextField textPemasok;
    private javax.swing.JTextField textTanggal;
    // End of variables declaration//GEN-END:variables

    private void updateData() {
        try {
            textKode.setEditable(true);
            textPemasok.setText("");
            textTanggal.setText(simpleDateFormat.format(new Date()));
            textKode.setText("");
            textKode.setEditable(true);
            listiItemPembelian.clear();
            updateTableItemNota();
            listReturPembelian.clear();
            updateTableReturPenjualan();
            listReturPembelianTemp.clear();
        } catch (Exception ex) {
            Logger.getLogger(FReturPembelian.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void updateTableItemNota() {
        String[] judul = {"No", "Kode", "Nama", "Satuan", "Jumlah", "Harga", "Sub Total"};
        Object[][] isi = new Object[listiItemPembelian.size()][7];
        int x = 0;
        int no = 0;
        for (ItemPembelian itemPembelian : listiItemPembelian) {
            isi[x][0] = no += 1;
            isi[x][1] = itemPembelian.getBarang().getKode();
            isi[x][2] = itemPembelian.getBarang().getNama();
            isi[x][3] = itemPembelian.getBarang().getSatuan().getNama();
            isi[x][4] = itemPembelian.getJumlah();
            isi[x][5] = "Rp " + numberFormat.format(itemPembelian.getHarga()) + ",00";
            isi[x][6] = "Rp " + numberFormat.format(itemPembelian.getHarga() * itemPembelian.getJumlah()) + ",00";
            x++;
        }
        tableItemPembelian.setModel(new DefaultTableModel(isi, judul) {

            @Override
            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return false;
            }
        });
        TableColumn column0 = tableItemPembelian.getColumnModel().getColumn(0);
        column0.setPreferredWidth(50);
        column0.setMaxWidth(50);
        column0.setCellRenderer(new CenterRenderer());
        TableColumn column1 = tableItemPembelian.getColumnModel().getColumn(1);
//        column0.setPreferredWidth(100);
//        column0.setMaxWidth(100);
        column1.setCellRenderer(new CenterRenderer());
        TableColumn column3 = tableItemPembelian.getColumnModel().getColumn(3);
//        column3.setPreferredWidth(75);
//        column3.setMaxWidth(75);
        column3.setCellRenderer(new CenterRenderer());
        TableColumn column4 = tableItemPembelian.getColumnModel().getColumn(4);
        column4.setCellRenderer(new CenterRenderer());
        TableColumn column5 = tableItemPembelian.getColumnModel().getColumn(5);
        column5.setCellRenderer(new RightRenderer());
        TableColumn column6 = tableItemPembelian.getColumnModel().getColumn(6);
        column6.setCellRenderer(new RightRenderer());
    }

    private void updateTableReturPenjualan() {
        String[] judul = {"No", "Kode", "Nama", "Satuan", "Jumlah"};
        Object[][] isi = new Object[listReturPembelian.size()][5];
        int x = 0;
        int no = 0;
        for (ReturPembelian returPembelian : listReturPembelian) {
            isi[x][0] = no += 1;
            isi[x][1] = returPembelian.getBarang().getKode();
            isi[x][2] = returPembelian.getBarang().getNama();
            isi[x][3] = returPembelian.getBarang().getSatuan().getNama();
            isi[x][4] = returPembelian.getJumlah();
            x++;
        }
        tableReturPembelian.setModel(new DefaultTableModel(isi, judul) {

            @Override
            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return false;
            }
        });
        TableColumn column0 = tableReturPembelian.getColumnModel().getColumn(0);
        column0.setPreferredWidth(50);
        column0.setMaxWidth(50);
        column0.setCellRenderer(new CenterRenderer());
        TableColumn column1 = tableReturPembelian.getColumnModel().getColumn(1);
//        column1.setPreferredWidth(100);
//        column1.setMaxWidth(100);
        column1.setCellRenderer(new CenterRenderer());
        TableColumn column3 = tableReturPembelian.getColumnModel().getColumn(3);
//        column3.setPreferredWidth(75);
//        column3.setMaxWidth(75);
        column3.setCellRenderer(new CenterRenderer());
        TableColumn column4 = tableReturPembelian.getColumnModel().getColumn(4);
//        column4.setPreferredWidth(75);
//        column4.setMaxWidth(75);
        column4.setCellRenderer(new CenterRenderer());
    }
}
